#ifndef SQLBASE_H
#define SQLBASE_H

#include <string>
#include "src/define/func_define.h"
#include "src/define/tupleeach.h"
#include <QVariant>
#include <QVariantList>
#include "MU_API.h"
#include <future>
#include <thread>
#include <string>
#include <utility>
#include <functional>
#include "src/SoftWare/DateTime/DateTime.h"


template<typename R = void, typename... Args>
class Fn {
public:
    Fn(std::function<R(Args...)> fun) : _fun(fun) {
    }

    R operator()(Args... args) {
        return _fun(args...);
    }
private:
    std::function<R(Args...) > _fun;
};

class SQLBase
{
public:
    SQLBase();


    virtual void ReLoad();
    virtual void ConnectToDB();
    virtual void DisConnect();
     virtual void insert(QString ,QStringList);
    //virtual void prepare(std::string,TableRet);
    virtual void Exec(std::string);
    virtual QVariantList Get(std::string);
    virtual QVariantList Get(std::string,std::initializer_list<std::string> ,std::initializer_list<std::string> );

    virtual void setDB(std::string db) ;
    virtual void setDBType(std::string type) ;

    std::string _db;
    std::string _db_type = "QSQLITE";


    std::string userName;
    std::string password;



    /**
     * @details 动态可变参数插入
     * @author 张鲜祥
     * @details 目前参数必须是std  string
     */
    template< typename... Args>
    static std::string prepare(std::string _query,Args...  mArgs){
        auto a = std::forward_as_tuple(mArgs...);
        _query+= " Values(";
        std::apply([&_query](auto&&... args){
            auto getValue = [&_query](auto t){
//                if(0 == strcmp("i" ,typeid (t).name())){
//                    // _query += to_string(t);
//                    _query += t;
//                }else{
//                    _query += t;
//                }
                _query += t;
                _query += ",";
                };
            ((getValue(args)), ...);
        },a);
        _query.pop_back();
        _query+= " );";
        return _query;
    }

};

#endif // SQLBASE_H
